package zc.cennavi.taxi;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import android.util.Log;

public class NetUtil {
	
	public String getStringByURL(String httpUrl){
		Log.v("time","httpUrl="+httpUrl);
		HttpGet httpRequest = new HttpGet(httpUrl);
		String strXML = "";
		try
		{
			HttpClient httpclient = new DefaultHttpClient();
			HttpResponse httpResponse = httpclient.execute(httpRequest);
			Log.v("time","code="+httpResponse.getStatusLine().getStatusCode());
			if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
			{
				strXML = EntityUtils.toString(httpResponse.getEntity());
			}
			else
			{
				return "";
			}
		}
		catch (ClientProtocolException e)
		{
			e.printStackTrace();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}  
		Log.v("time", "strXML="+strXML);
		return strXML;
	}
	
	public String getIndex(double lon,double lat){
		double lon02 = lon-0.0065;
		double lat02 = lat-0.00635;
		Log.v("time", "lon02="+lon02);
		Log.v("time", "lat02="+lat02);
		Log.v("time", "url="+"http:\\taxi.trafficeye.cn/TaxiIndex/tq?action=1&lon="+lon02+"&lat="+lat02+"&city=010&catalog=1");
		return getStringByURL("http://taxi.trafficeye.cn/TaxiIndex/tq?action=1&lon="+lon02+"&lat="+lat02+"&city=010&catalog=1");
		
//		return getStringByURL("http://taxi.trafficeye.cn/TaxiIndex/tq?action=1&lon="+"116.461749"+"&lat="+"39.908355"+"&city=010&catalog=1");
	}
	public String getEmptyTaxi(double lon,double lat){
		return getStringByURL("http://taxi.trafficeye.cn/TaxiIndex/tq?action=2&lon="+lon+"&lat="+lat+"&radius=0.012&catalog=1");
	}
	public String getHotPoint(double lon,double lat){
		return getStringByURL("http://taxi.trafficeye.cn/TaxiIndex/tq?action=3&city=010&lon="+lon+"&lat="+lat+"&radius=1.0535&catalog=1");
	}
	public String getHistoryPoint(double lon,double lat){
		return getStringByURL("http://taxi.trafficeye.cn/TaxiIndex/tq?action=4&lon="+lon+"&lat="+lat+"&radius=0.018&catalog=1");
	}

}
